package com.it.util;

import java.util.Arrays;
import java.util.Random;

public class RandomNum {
    public static void main(String[] args) {
        int n;
        Random random = new Random();
        int[] array = new int[20];
        for (int i = 0; i < array.length; i++) {
            array[i]=random.nextInt(100);
        }

        System.out.println("随机生成的数组为:"+ Arrays.toString(array));

        System.out.println("随机数:"+getRanInArr(array));
    }

    static int getRanInArr(int[] array){
        int length=array.length;
        /*Random random = new Random();
        int index=random.nextInt(length)+1;*/
        int index= (int) (Math.random()*length);
        return array[index];
    }

    public static int getNum() {
        int[] ints = new int[4];
        ints[0]=0;
        ints[1]=1;
        ints[2]=5;
        ints[3]=10;
        return getRanInArr(ints);
    }
}
